#include <stdio.h>
#include <stdlib.h>
#include "seqstack.h"
//判断满
void test_IsFullSeqStack(seqstack_t *kong,seqstack_t *feikong,seqstack_t *man,seqstack_t *p){
    printf("__________判断是否为满test________\n");
//p == NULL
    {
        if(IsFullSeqStack(NULL) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//p->data == NULL
    {
        if(IsFullSeqStack(p) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
        p->data=NULL;
    }
//栈未满
//栈为空
    {
        if(IsFullSeqStack(kong) == 0){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈不为空,但也不满
// 入栈操作
    {
        if(IsFullSeqStack(feikong) == 0){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈满
    {
        if(IsFullSeqStack(man) == 1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
    printf("__________判断是否为满test________\n");
}
//判断入栈
void test_PushStack(seqstack_t *man){
    printf("__________入栈test________\n");
//p == NULL
{
    
    if(PushStack(NULL,0) == -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
}
//P != NULL
//p->data == NULL
{
    seqstack_t *pa= CreateEpSeqStack(5);
    if(pa == NULL){
        printf("栈创建失败\n");
        return;
    }
    free(pa->data);
    pa->data=NULL;
    if(PushStack(pa,3) == -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
    free(pa);
    pa=NULL;
}
//p->data != NULL
{
    seqstack_t *pb= CreateEpSeqStack(5);
    if(pb == NULL){
        printf("栈创建失败\n");
        return;
    }
    if(PushStack(pb,3) == 1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
    free(pb->data);
    pb->data=NULL;
    free(pb);
    pb=NULL;
}
//栈满
{
    if(PushStack(man,3) == -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
}
    printf("__________入栈test________\n");
}
//判断空
void test_IsEpSeqStack(seqstack_t *kong,seqstack_t *feikong,seqstack_t *man,seqstack_t *p){
    printf("__________判断是否为空test________\n");
//p == NULL
    {
        if(IsEpSeqStack(NULL) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//p->data == NULL
    {   
        p->data=NULL;
        if(IsEpSeqStack(p) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈未满
//栈为空
    {
        if(IsEpSeqStack(kong) == 0){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈不为空
// 入栈操作
    {
        if(IsEpSeqStack(feikong) == 1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }

    printf("__________判断是否为空test________\n");
}
//判断出栈
void test_PopSeqStack(seqstack_t *man){
//p == NULL
{
    if(PopSeqStack(NULL) == -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
}
//P != NULL
//p->data == NULL
{
    seqstack_t *pa= CreateEpSeqStack(5);
    if(pa == NULL){
        printf("栈创建失败\n");
        return;
    }
    free(pa->data);
    pa->data=NULL;
    if(PopSeqStack(pa) == -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
    free(pa);
    pa=NULL;
}
//p->data != NULL  栈为空
{
    seqstack_t *pb= CreateEpSeqStack(5);
    if(pb == NULL){
        printf("栈创建失败\n");
        return;
    }
    if(PopSeqStack(pb) == -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
    free(pb->data);
    pb->data=NULL;
    free(pb);
    pb=NULL;
}
//栈不为空
{
    if(PopSeqStack(man) != -1){
        printf("正确\n");
    }
    else{
        printf("错误\n");
    }
}
    printf("__________入栈test________\n");

}
//判断清除
void test_ClearSeqStack(){
    printf("__________判断清除test________\n");
//p == NULL
{
        ClearSeqStack(NULL);
}
//p != NULL
{
    seqstack_t *pa= CreateEpSeqStack(5);
    if(pa == NULL){
        printf("栈创建失败\n");
        return;
    }
    PushStack(pa, 1);
    PushStack(pa, 2);
    PushStack(pa, 3);
    ClearSeqStack(pa);
    printf("pa->top=%d\n",pa->top);
    free(pa->data);
    pa->data=NULL;
    free(pa);
    pa=NULL;
}
    printf("__________判断清除test________\n");
}
//判断获取栈顶部数据
void test_GetTopSeqStack(seqstack_t *kong,seqstack_t *feikong,seqstack_t *p){
    printf("__________判断获取栈顶数据test________\n");
//p == NULL
    {
        if(GetTopSeqStack(NULL) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//p->data == NULL
    {   
        p->data=NULL;
        if(GetTopSeqStack(p) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈为空
    {
        if(GetTopSeqStack(kong) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈不为空
    {
        if(GetTopSeqStack(feikong) == 3){
            printf("顶部数据为3\n");
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }

    printf("__________判断获取栈顶数据test________\n");
}
//判断求栈的长度
void test_LengthSeqStack(seqstack_t *kong,seqstack_t *feikong,seqstack_t *p){
    printf("__________判断求栈的长度test________\n");
//p == NULL
    {
        if(LengthSeqStack(NULL) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//p->data == NULL
    {   
        p->data=NULL;
        if(LengthSeqStack(p) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈为空
    {
        if(LengthSeqStack(kong) == -1){
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }
//栈不为空
    {
        if(LengthSeqStack(feikong) == 3){
            printf("长度为3\n");
            printf("正确\n");
        }
        else{
            printf("错误\n");
        }
    }

    printf("__________判断求栈的长度test________\n");
}


int main(void) {
//创建空栈
    seqstack_t *kong= CreateEpSeqStack(5);
        if(kong == NULL){
            printf("栈创建失败\n");
        return  -1;
        }
//创建非空不满栈
    seqstack_t *feikong= CreateEpSeqStack(5);
        if(feikong == NULL){
            printf("栈创建失败\n");
            return -1;
        }

        PushStack(feikong, 1);
        PushStack(feikong, 2);
        PushStack(feikong, 3);
//创建满栈
    seqstack_t *man= CreateEpSeqStack(5);
        if(man == NULL){
            printf("栈创建失败\n");
            return -1;
        }

        PushStack(man, 1);
        PushStack(man, 2);
        PushStack(man, 3);
        PushStack(man, 4);
        PushStack(man, 5);
//创建p->data==NULL;
    seqstack_t *p= CreateEpSeqStack(5);
    if(p == NULL){
        printf("栈创建失败\n");
        return -1;
    }
    free(p->data);
    p->data=NULL;
//test
    test_IsFullSeqStack(kong,feikong,man,p);
    test_PushStack(man);
    test_IsEpSeqStack(kong,feikong,man,p);
    test_PopSeqStack(man);
    test_ClearSeqStack();
    test_GetTopSeqStack(kong,feikong,p);
    test_LengthSeqStack(kong,feikong,p);
//释放空
    free(kong->data);
    kong->data=NULL;
    free(kong);
    kong=NULL;
//释放非空
    free(feikong->data);
    feikong->data=NULL;
    free(feikong);
    feikong=NULL;
//释放满
    free(man->data);
    man->data=NULL;
    free(man);
    man=NULL;
//释放
    free(p);
    p=NULL;

    return 0;
}
